<template>
  <div class="books">
    <!-- 标题 -->
    <div class="title">
      追漫 <span @click="remove">{{ showBtn ? "取消" : "编辑" }}</span>
    </div>
    <!-- 收藏 -->
    <div class="list">
      <ul>
        <cartoon-list :recommend="arr" :remove="showBtn">
          <li class="add" v-if="!showBtn" @click="add">
            <div></div>
          </li>
        </cartoon-list>
      </ul>
    </div>
    <div class="btn" v-if="showBtn" @click="yes">确认删除</div>
  </div>
</template>

<script>
import CartoonList from "../components/CartoonList.vue";
import { Toast } from "vant";
export default {
  name: "Books",
  data() {
    return {
      showBtn: false,
      arr: [],
    };
  },
  components: {
    CartoonList,
  },
  props: ["tongbu"],
  methods: {
    remove() {
      if (this.$route.query.isLogin == "true") {
        if (this.showBtn == false) {
          this.showBtn = true;
        } else {
          this.showBtn = false;
          this.tongbu.forEach((item) => {
            item.select = 0;
          });
        }
      } else {
        Toast("请先登录！");
      }
    },
    add() {
      if (this.$route.query.isLogin == "true") {
        this.$router.push(`/more?isLogin=${this.$route.query.isLogin}`);
      } else {
        Toast("请先登录！");
      }
    },
    yes() {
      this.showBtn = false;
      this.arr = this.arr.filter((item) => {
        return !item.select;
      });
      // console.log(0, this.arr);
      this.$emit("item-remove", this.arr);
    },
  },
  mounted() {
    this.arr = this.tongbu;
    this.tongbu.forEach((item) => {
      item.select = 0;
    });
  },
};
</script>

<style lang="scss" scoped>
@import "@/static/common/base.scss";

.books {
  width: 100%;
  padding: $p;
  // 标题
  .title {
    padding: 5vw;
    text-align: center;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    position: relative;
    span {
      position: absolute;
      right: 0;
      top: 39%;
      font-weight: normal;
      font-size: 3.2vw;
    }
  }
  .list {
    margin-top: 2.6667vw;
    padding: 0;
    ul {
      display: flex;
      flex-wrap: wrap;
      // justify-content: space-between;
      li:nth-child(3n) {
        margin-right: 0;
      }
      li {
        width: 31%;
        margin-bottom: 5vw;
        margin-right: 3vw;

        img {
          width: 100%;
        }
      }
      .add {
        height: 46.1333vw;
        div {
          display: block;
          border: 1px solid $bgc;
          width: 100%;
          height: 37.3333vw;
          background: url("../assets/加.png") no-repeat center;
          background-size: 30%;
        }
      }
    }
  }
  .btn {
    width: 20vw;
    height: 10vw;
    line-height: 10vw;
    text-align: center;
    border-radius: 5vw;
    color: #fff;
    position: absolute;
    bottom: 17vw;
    left: 40%;
    background-color: $bgc;
    font-size: 3.7333vw;
  }
}
</style>
